import time
from multiprocessing import Process, Queue


# 通过multiprocessing中的Queue队列来实现进程间通信

def put(qx):
    for i in range(10):
        print('入队', i)
        qx.put(i)


def get(qx):
    while True:
        print("出队", qx.get())
        # 必须的要加,避免队列为空的时候，直接break,造成队列里面一直阻塞
        time.sleep(1)
        if qx.empty():
            print("队列为空")
            break


if __name__ == '__main__':
    q = Queue(3)
    p1 = Process(target=put, args=(q,))
    p2 = Process(target=get, args=(q,))
    p1.start()
    p2.start()
    p1.join()
    p2.join()
    print("结束")
